/* Example 1 by Maxim Zhuravlev*/
#include <stdio.h>
#include <stdlib.h>

/* Calculates sum of integers diveded by line breaks in the file given. 
* No check for overflow.
* Result if file is missing is zero.  
*/
int calculate_sum(char const * const file_name)
{
	FILE *f = fopen(file_name, "rt");
	int current_num = 0;
	int sum = 0;
	if (f != NULL) 
	{
		while (fscanf(f, "%d", &current_num) > 0)
		{
			sum += current_num;
		}
		fclose(f);
	}
	else
	{
		sum = 0;
		fprintf(stderr, "Cannot open file %s\n", file_name);
	}

	return sum;
}



int main (int Argn, char * Args[]) 
{
  char file_name[] = "numbers.txt";
  printf("Sum of numbers is %d\n", calculate_sum(file_name));
  system("pause");
  return 0;
}